//
//  AchievementView.swift
//  JTYP
//
//  Created by Groot on 2017/12/5.
//  Copyright © 2017年 inspur. All rights reserved.
//

class AchievementView: UIView {
    
    static let viewHeight = 35
    
    var pedometer: Int = 0 {
        didSet {
            if pedometer > 3045 {
                titleLab.text = "您已步入日运动达人阵营，银色达人阵营正向您招手!"
                if self.isHidden {
                    self.isHidden = false
                    UIView.animate(withDuration: 1.0, animations: {
                        self.alpha = 1
                    })
                }
            }else {
                titleLab.text = ""
                UIView.animate(withDuration: 1.0, animations: {
                    self.alpha = 0
                }, completion: { (b) in
                    if b {
                        self.isHidden = true
                    }
                })
            }
        }
    }
    
    // 成就标语
    private lazy var titleLab: UILabel = {
       var lab = UILabel()
        lab.textColor = DefaultColor.green
        lab.font = UIFont.systemFont(ofSize: 13)
        return lab
    }()
    
    // 右侧箭头
    private lazy var arrowIcon: UIImageView = {
        var imgView = UIImageView.init(image: UIImage.init(named: "arrow_right"))
        return imgView
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        customization()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        customization()
    }
    
    func customization() {
        let l2 = UIView()
        l2.backgroundColor = DefaultColor.line
        addSubview(l2)
        l2.snp.makeConstraints { (make) in
            make.height.equalTo(1)
            make.leading.trailing.bottom.equalToSuperview()
        }
        
        addSubview(arrowIcon)
        arrowIcon.snp.makeConstraints { (make) in
            make.trailing.equalToSuperview().offset(-8)
            make.centerY.equalToSuperview()
            make.size.equalTo(CGSize.init(width: 10, height: 15))
        }
        addSubview(titleLab)
        titleLab.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.leading.equalToSuperview().offset(16)
            make.right.equalTo(arrowIcon.snp.left).offset(-8)
        }
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
    }
}
